#!/bin/bash

IMAGE_NAME="cnpbweb_image"
CONTAINER_NAME="cnpbweb_container"

docker stop $CONTAINER_NAME

# 检查并删除旧容器
if docker ps -a | grep -q "$CONTAINER_NAME"; then
    docker rm $CONTAINER_NAME
    echo "旧容器已删除"
else
    echo "未找到现存容器"
fi

# 检查并删除旧镜像
if docker images | grep -q "$IMAGE_NAME"; then
    docker rmi $IMAGE_NAME
    echo "旧镜像已删除"
else
    echo "未找到现存镜像"
fi

# 构建新镜像
docker build -t $IMAGE_NAME .

# 运行新容器
docker run -d -p 10011:80 --name $CONTAINER_NAME $IMAGE_NAME